package com.woniu.user.mqlistener;

import com.woniu.user.exception.WebException;
import com.woniu.user.exception.WebExceptionCode;
import com.woniu.user.service.AccountService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Arrays;

@Component// 将本类对象注入ioc容器
@RocketMQMessageListener(topic = "code-topic", consumerGroup = "code-group")
public class CodeListener implements RocketMQListener<String[]> {

    @Resource
    private AccountService accountService;

    @Override
    public void onMessage(String[] param) {
        try {
            accountService.sendMail(param[0], param[1], param[2]);
        } catch (MessagingException e) {
            throw new WebException(WebExceptionCode.MAIL_SEND_FAILED);
        }
    }
}
